package exception;

public class Student {
    private String name;//姓名
    private int age;//年龄

    public String getName() {//获取
        return name;
    }

    public void setName(String name) {//设置
        this.name = name;
    }

    public int getAge() {
        return age;
    }
//设置年龄
    public void setAge(int age) throws AgeException {//继续抛出异常，谁调用谁处理
        if (age<0) throw  new AgeException();//如果输入的数字小于0，则抛出异常
        this.age = age;
    }
    public static void main(String[] args){
        Student s=new Student();
        try {
            s.setAge(3);
        } catch (AgeException e) {
            System.out.println(e.getMessage());
        }
    }
}